package com.zhongyu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongyu.pojo.Goods;
import com.zhongyu.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

public interface OrderMapper extends BaseMapper<Order> {
    /**
     * 所有销售订单查询
     * @param page
     * @return            "left  join smbms_user t4 on t1.CHECKER=t4.id \n"+
     */
    @Select("select *  from smbms_order ${ew.customSqlSegment} ")
    List<Order> findAll(Page page ,@Param("ew") Wrapper wrapper);
    /**
     * 未出库销售订单查询
     * @param page
     * @return            "left  join smbms_user t4 on t1.CHECKER=t4.id \n"+
     */
    @Select("select * from smbms_order t1 where t1.type=2 and t1.state=0")
    List<Order> findAll2(Page page);

    //采购申请页面分页显示
    @Select("SELECT * FROM smbms_order ")
    List<Order> find(Page page , @Param("ew") Wrapper wrapper);

    /**
     * 根据销售订单id 查订单详情
     * @param id
     * @return
     */
 /*  "SELECT t1.*,t3.id,t3.* ,t2.id,t2.*,t4.*,t5.username FROM smbms_order\n t1"
           "LEFT  JOIN smbms_Kehu t3 ON t1.provider_id=t3.id\n"
           "LEFT  JOIN smbms_order_detail t2 ON t1.id=t2.order_id\n"
           " LEFT  JOIN smbms_cangku t4 ON t4.id=t2.storehouse_id\n"
           " LEFT  JOIN smbms_user t5 ON t5.id=t4.user_id\n"
           " WHERE t1.type=2 AND t1.id=#{id}"*/
    @Select("SELECT t1.* ,t2.detail_id,t2.* FROM smbms_order t1\n"+
            "LEFT  JOIN smbms_order_detail t2 ON t1.id=t2.order_id \n"+
            " WHERE t1.type=2 AND t1.id=#{id} " )
    @ResultMap("orderRm")
    List<Order>findById(Integer id);










    //采购

    /**
     *查询所有采购订单
     * @param
     * @return
     */
    @Select("SELECT * FROM smbms_order ${ew.customSqlSegment} ")
    List<Order> findAll1(Page page,@Param("ew") Wrapper wrapper);
    /**
     * 采购订单查询
     */
    @Select("select * from smbms_order_detail where id=#{id}")
    List<Order> findAllCC(Integer id);

    @Select("select * from smbms_order where id=#{id}")
    List<Order> findAllOrder(Integer id);
}
